﻿if (!DRINKLOCATOR) {
    var DRINKLOCATOR = {};
}


if (!DRINKLOCATOR.Map) {
        DRINKLOCATOR.Map = {};
}

if (!DRINKLOCATOR.GetMap) {
    DRINKLOCATOR.GetMap = function (mapCredentials, results) {
        //alert(results.length);
        var mapOptions = {
            credentials: mapCredentials,
            height: 480,
            width: 640,
            mapTypeId: Microsoft.Maps.MapTypeId.road,
            zoom: 12
        }; // end mapOptions
        //,            mapTypeId: Microsoft.Maps.MapTypeId.aerial

        DRINKLOCATOR.Map = new Microsoft.Maps.Map(document.getElementById("storesMap"), mapOptions);
        //map = new VEMap('storesMap');
        //map.SetCredentials("@ViewBag.MapCredentials");
        //map.LoadMap();
        //var results = @Html.JsonSerialize(Model);

        for (var i = 0; i < results.length; i++) {
            var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(results[i].Latitude, results[i].Longitude));
            DRINKLOCATOR.Map.entities.push(pin);
        }

        DRINKLOCATOR.Map.setView({ center: new Microsoft.Maps.Location(results[0].Latitude, results[0].Longitude) });
    }; // end GetMap Function
}
